/** 
 * ***** 模板定义 ******
 * @name    controller
 * @description    控制器
 * @ext    java
 * @targetPath    @projectRoot/mario-web/src/main/java/com/wangjiang/mario/admin/web/admin/controller/v1
 *
 * ***** 模板变量定义 ******
 * @variable    desc|控制器|控制器
 * @variable    model|modelName|model
 */

package com.wangjiang.mario.admin.web.admin.controller.v1;

import com.wangjiang.mario.admin.common.base.BaseController;
import com.wangjiang.mario.admin.common.object.UUidList;
import com.wangjiang.mario.admin.common.object.UUidListForBatchUpdate;
import com.wangjiang.mario.admin.common.rest.ResultGenerator;
import com.wangjiang.mario.admin.common.rest.entity.Result;
import com.wangjiang.mario.admin.system.domain.components.ConfigComponent;
import com.wangjiang.mario.admin.system.domain.entity.<{model_first_upper}>Entity;
import com.wangjiang.mario.admin.system.domain.service.<{model_first_upper}>Service;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * <{desc}>
 *
 * @author <{root.author}>
 * @datetime <{root.now_datetime}>
 */

@RestController
@RequestMapping("/<{model_first_lower}>")
@Api(value = "/<{model_first_lower}>", tags = "<{desc}>")
public class <{model}>Controller extends BaseController<<{model_first_upper}>Entity> {

    private static final Logger logger = LoggerFactory.getLogger(<{model}>Controller.class);

    @Autowired
    private ConfigComponent configComponent;

    @Autowired
    private <{model}>Service <{model_first_lower}>Service;

    @GetMapping("")
    public Result list (
             <{model_first_upper}>Entity,
            @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        return ResultGenerator.genSuccessResult(baseService.basePage(currentPage, pageSize, qo, <{model_first_upper}>Entity.class));
    }

    /**
     * 根据uuid 获取实体信息
     *
     * @param uuid
     * @return
     */
    @GetMapping("/{uuid}")
    public Result getOne (@PathVariable String uuid) {
        return ResultGenerator.genSuccessResult(baseService.baseGetByUUid(uuid, <{model_first_upper}>Entity.class));
    }

    @GetMapping("/all")
    public Result all (<{model_first_upper}>Entity qo) throws IllegalAccessException {
        return ResultGenerator.genSuccessResult(baseService.list(qo));
    }

    @PostMapping("")
    public Result create (@RequestBody <{model_first_upper}>Entity entity) {
        return ResultGenerator.genSuccessResult(baseService.baseSave(entity));
    }

    @PutMapping("")
    public Result update(@RequestBody <{model_first_upper}>Entity entity) {
        return ResultGenerator.genSuccessResult(baseService.baseUpdateById(entity));
    }

    @PutMapping("/batch")
    public Result batchUpdate(
            @RequestBody UUidListForBatchUpdate<<{model_first_upper}>Entity> uuidListForBatchUpdate
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseUpdateBatch(uuidListForBatchUpdate));
    }

    @DeleteMapping("")
    public Result delete(
            @RequestParam String uuid
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseSoftRemoveById(uuid));
    }

    @DeleteMapping("/batch")
    public Result batchDelete(
            @RequestBody UUidList uuidList
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseBatchSoftRemoveByUUidList(uuidList));
    }
}
